export function create(dom, { text = '水印', color = '#ccc', subtext = '' }) {
    if (!dom || dom.__watermark) return;
    if (typeof dom === 'string') dom = document.querySelector(dom);

    var canvas = document.createElement('canvas')
        canvas.width = 150
        canvas.height = 150
        canvas.style.display = 'none'
        //绘制文字
        var ctx = canvas.getContext('2d')
        ctx.rotate(-45 * Math.PI / 180)
        ctx.translate(-75, 25)
        ctx.fillStyle = color
        ctx.font = "bold 20px SimHei"
        ctx.textAlign = "center"
        ctx.fillText(text, canvas.width / 2, canvas.height / 2)
        ctx.font = "14px Microsoft YaHei"
        ctx.fillText(subtext, canvas.width / 2, canvas.height / 2 + 20)
        //创建水印容器
        var watermark = document.createElement('div')
        watermark.setAttribute('class', 'watermark')
        const styleStr = `position:absolute;top:0;left:0;right:0;bottom:0;z-index:99;pointer-events:none;background-repeat:repeat;background-image:url('${canvas.toDataURL("image/png")}');`
        watermark.setAttribute('style', styleStr);

    dom.appendChild(watermark);

    dom.__watermark = watermark;
}

export default create;